<html>
<script>
    console.log("1")


    // setTimeOut函数不设置时间
    setTimeout ( () => {
        console.log('2')
        new Promise( (resolve => {
            console.log("3")
            resolve()
        })) .then ( () => {
            setTimeout(()=>{
                console.log('9')
            })
            console.log("4")
        })
    })


    new Promise ( (resolve, reject) => {
        console.log("5")
        resolve()
    }) .then( () => console.log('6'))


    setTimeout ( () => {
        console.log('7')
        setTimeout ( () => {
            console.log('10')
            new Promise((resolve=>{
                console.log('11')
                resolve()
            })).then(()=>{
                console.log('12')
            })
        })
    })


    console.log("8")

    /*
    * 1 5 8 6 2 3 4 7
    *
    * 执行主线程 console.log(1),然后把第七行的settimeout(2,3,4)加入宏任务队列，接下来执行16行new Promise立即打印console.log(5),
    * 接着将then(console.log(6)) 加入微任务队列. 接着将setTimeout(7)加入宏任务队列,执行console.log(8)
    * 接着执行微任队列打印 setTimeout(6)
    * 执行setTimeout(2,3,4),立即打印log(2)然后执行new Promise 立即打印log(3),调用resolve后把then(4)加入微任务队列
    *
    *
    *
    *------------------------------------------
    * 宏任务队列 setTimeout(2,3,4) setTimeout(7)
    * 微任务队列 then(console.log(6))
    *------------------------------------------
    * 宏任务队列 setTimeout(2,3,4) setTimeout(7)
    * 微任务队列
    *------------------------------------------
    * 宏任务队列 setTimeout(7)
    * 微任务队列
    *------------------------------------------
    * 宏任务队列 setTimeout(7)
    * 微任务队列 then(4)
    *------------------------------------------
    * 宏任务队列 setTimeout(7)
    * 微任务队列
    *------------------------------------------
    * 宏任务队列 setTimeout(7)
    * 微任务队列
    *------------------------------------------
    */
</script>
</html>
